import { defineStore } from "pinia";

export const userInfoStore = defineStore('userInfoStore', {
    state: () => ({
        userId: 0,
        username: 'username',
        name:'name',
        authority: 3,
        password: 'password',
        remarks: 'remarks',
        authorityName: 'authorityName'
    }),
    getters: {
        getUserId(){
            return this.userId
        },
        getUsername(){
            return this.username
        },
        getName(){
            return this.name
        },
        getAuth(){
            return this.authority
        },
        getPwd(){
            return this.password
        },
        getRemarks(){
            return this.remarks
        },
        getAuthName(){
            return this.authorityName
        },
    },
    actions: {
        setAll(userInfo) {
            this.userId = userInfo.userId;
            this.username = userInfo.username;
            this.name = userInfo.name;
            this.authority = userInfo.authority;
            this.password = userInfo.password;
            this.remarks = userInfo.remarks;
            this.authorityName = userInfo.authorityName;
        },
        setName(name) {
            this,name = name;
        },
    },
    persist: {
        enabled: true, // true 表示开启持久化保存
        strategies: [
            {
                key: 'userStore',
                storage: localStorage,
                paths: ['userId','username','name','authority','password','remarks','authorityName'],
            },
          ],
    },
})

export const collapseStore = defineStore('collapseStore',{
    state: () => ({
        collapse: false,
    }),
    getters: {
        getCollapse(){
            return this.collapse
        },
    },
    actions: {
        setCollapse(collapse) {
            this.collapse = collapse
        }
    }
})